//
//  BlueViewController.m
//  TestPushAndPresent
//
//  Created by sunhongyue on 2017/6/25.
//  Copyright © 2017年 sunhongyue. All rights reserved.
//

#import "BlueViewController.h"
#import "GreenViewController.h"

@interface BlueViewController ()

@end

@implementation BlueViewController

- (instancetype)init {
    if (self = [super init]) {
        self.view.backgroundColor = [UIColor blueColor];
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIBarButtonItem *rightBtnItem = [[UIBarButtonItem alloc] initWithTitle:@"push" style:UIBarButtonItemStylePlain target:self action:@selector(rightBarItemAction:)];
    self.navigationItem.rightBarButtonItem = rightBtnItem;
    
    UIBarButtonItem *leftBtnItem = [[UIBarButtonItem alloc] initWithTitle:@"left" style:UIBarButtonItemStylePlain target:self action:@selector(leftBarItemAction:)];
    self.navigationItem.leftBarButtonItem = leftBtnItem;
    
    // Do any additional setup after loading the view.
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectZero];
    [self.view addSubview:button];
    button.translatesAutoresizingMaskIntoConstraints = NO;
    [button.widthAnchor constraintEqualToConstant:100.0].active = YES;
    [button.heightAnchor constraintEqualToConstant:50.0].active = YES;
    [button.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor].active = YES;
    [button.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor].active = YES;
    [button addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"dismiss Self" forState:UIControlStateNormal];
    button.backgroundColor = [UIColor greenColor];
    
    
    
    UIButton *button2 = [[UIButton alloc] initWithFrame:CGRectZero];
    [self.view addSubview:button2];
    button2.translatesAutoresizingMaskIntoConstraints = NO;
    [button2.widthAnchor constraintEqualToConstant:100.0].active = YES;
    [button2.heightAnchor constraintEqualToConstant:50.0].active = YES;
    [button2.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor].active = YES;
    [button2.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor constant:100].active = YES;
    [button2 addTarget:self action:@selector(btnAction2:) forControlEvents:UIControlEventTouchUpInside];
    [button2 setTitle:@"presnetGreen" forState:UIControlStateNormal];
    button2.backgroundColor = [UIColor greenColor];
}

- (void)rightBarItemAction:(id)sender {
    GreenViewController *greenVC = [[GreenViewController alloc] init];
    [self.navigationController pushViewController:greenVC animated:YES];
}

- (void)leftBarItemAction:(id)sender {
    // pop
    [self.navigationController popViewControllerAnimated:YES];
    
}


- (void)btnAction:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

- (void)btnAction2:(UIButton *)sender {
    GreenViewController *greenVC = [[GreenViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:greenVC];
    [self presentViewController:nav animated:YES completion:^{
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
